<?php
class controller_Game extends base_module
{
    protected $Game;

    public function __construct()
    {
        $this->Game = RpcClient::instance("Game");
        parent::__construct();
    }
    public function index()
    {
        $result = $this->Game->GameHomeData();
        $result['state']= 200;
        echo json_encode($result);
    }
    public function gametimeout(){
        $data = $this->Game->timeOutRedEnveloes($this->paras);
        if($data['state']= 200)
        {
            $result = $data['data'];
            echo json_encode($result);
        }else{
            echo json_encode($this->result);
        }
    }
    public function gamelist()
    {
        $data = $this->Game->GameHomeData();
        if($data['state']= 200)
        {
            $result = $data['data'];
            $result['state'] = 200;
            //$result['online'] = $data['online'];
            echo json_encode($result);
        }else{
            echo json_encode($this->result);
        }
    }
    public function grabgameenvelopes()
    {
        if(empty($this->paras['cmd'])
            OR empty($this->paras['room_id'])
            OR empty($this->paras['game_id'])
            OR empty($this->paras['red_issue'])
            OR empty($this->paras['token'])){
            echo json_encode(array(
                'state'=>404,
                'msgid'=>404,
                'info'=>'参数不正确',
            ));
            return;
        }
        $data = $this->Game->grabGameEnvelopes($this->paras);

        if($data['state']= 200 && isset($data['data']))
        {
            $result = $data['data'];
            echo json_encode($result);
        }else{
            echo json_encode($this->result);
        }
    }
    public function randenvelopes(){
        //var_dump($this->paras);
        $data = $this->Game->divideGameRedPackage($this->paras);
        if($data['state']==200){
            $result = $data['data'];
            echo json_encode($result);
        }else{
            echo json_encode($this->result);
        }
    }

    # 正在进行中的房间
    public function roomsGameList()
    {
        $data = $this->Game->roomsGameList($this->paras);
        if($data['state']==200){
            $result = $data['data'];
            echo json_encode($result);
        }else{
            echo json_encode($this->result);
        }
    }
}